home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / copymove.swg / 0021_Fastest copy for the media.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1995-02-28  |  2.7 KB  |  72 lines

  1. {
  2.  MC> That's really important, for what you've tested and shown.
  3.  MC> However, your specific values don't apply to everyone, as smaller HDs
  4.  MC> have smaller sector sizes (4096, 2048, etc.).  In order for your thesis
  5.  MC> to work best, the code/logic should also determine the HD sector size,
  6.  MC> before allocating buffers and trying to maximize performance to this
  7.  MC> degree.  That gets down into some pretty low-level code...
  8.  
  9.      It wouldn't be "that" tough really (if you wanted to do it). You simply
  10. make the buffer as large as the optimum size for the smallest cluster size
  11. which is 64512 (1024*63). Then do your blockread/blockwrites based on the
  12. optimal number for the current cluster size. It is, after all, the size of the
  13. block to read/write which is adversely affecting the speed, and not the size
  14. of the buffer itself.
  15.      It would look something like this.
  16. }
  17.  
  18. Uses Dos;
  19.  
  20. Const
  21. maxarray = 64512;
  22.  
  23. Var
  24. regs        :registers;
  25. buf         :array[1..maxarray] of char;
  26. fil1,
  27. fil2        :file;
  28. maxread,
  29. numread,
  30. numwritten,
  31. clustSize   :word;
  32.  
  33. begin
  34.    regs.cx := 0;                        {set for error-checking}
  35.    regs.ax := $3600;                    {get free space}
  36.    regs.dx := 0;                        {0=current, 1=a:, 2=b:, etc.}
  37.    msDos (regs);
  38.    clustsize := regs.ax * regs.cx;      {cluster size}
  39.    maxread := maxarray - (maxarray mod clustsize);
  40.              {the largest number of bytes ("char"s) evenly divisible
  41.               by the cluster size that will fit in our array}
  42.    assign(fil1,paramstr(1));
  43.    assign(fil2,paramstr(2));
  44.    reset(fil1,1);
  45.    rewrite(fil2,1);
  46.    repeat
  47.       blockread(fil1,buf,maxread,numread);
  48.       blockwrite(fil2,buf,numread,numwritten);
  49.       until ((eof(fil1)) or (numwritten=0));
  50.    close(fil1);
  51.    close(fil2);
  52.    end.
  53.  
  54. Error checking not included!!
  55.  
  56.      You may wish to redefine "regs.dx" above if the copy drive is other than
  57. current, but you will likely find this gives you the fastest "copy" regardless
  58. of the cluster size of the medium. With the noteable exception that if you
  59. had a medium with 512 byte clusters, the above optimal number "could" be
  60. increased by 512 if the variables were otherwise defined. (Placing the buffer
  61. in the heap for instance.) Not that any drive with a 512 byte cluster is
  62. really worth the trouble <G> but if you were going to put "buf" in the heap
  63. then you should consider using maxarray = 65024 (127*512) instead of 64512.
  64.  
  65. Dave...
  66.  
  67. --- GEcho 1.11+
  68.  * Origin: Forbidden Knights Systems * (905)820-7273 * Dual * (1:259/423.0)
  69. SEEN-BY: 250/99 101 201 301 401 470 501 601 701 801 901 259/0
  70. SEEN-BY: 259/99 200 303 400 423 500 396/1 3615/50 51
  71. PATH: 259/423 400 99 250/99 3615/50
  72.